package com.young.shop.pojo.vo;

/**
 * 标准内容返回对象类型
 */
public class BaseRespVO<T> {
	//    状态：成功，业务失败，未登录
	private int code = CodeType.SUCCESS.getValue();
	//    失败提示信息
	private String msg;
	//    业务信息
	private T data;

	public enum CodeType {
		SUCCESS(100), FAILED(101), UN_LOGIN(200);
		private int value;

		CodeType(int value) {


			this.value = value;
		}

		public int getValue() {
			return value;
		}
	}

	private static BaseRespVO instance;

	public static BaseRespVO getInstance() {

		return instance;
	}

	//成功标准返回
	public BaseRespVO success(T data) {
		BaseRespVO result = new BaseRespVO<T>();
		result.setData(data);
		return result;
	}

	//失败标准返回
	public BaseRespVO failed(String msg) {
		BaseRespVO result = new BaseRespVO<T>();
		result.setCode(CodeType.FAILED.getValue());
		result.setMsg(msg);
		return result;
	}


	@Override
	public String toString() {
		return "BaseRespVO{" +
				"code=" + code +
				", msg='" + msg + '\'' +
				", data=" + data +
				'}';
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}
}
